package mvc.views.mediators
{
	import globals.Global;
	
	import mvc.Notifications;
	import mvc.models.proxys.ProxyAuth;
	import mvc.views.frames.FrameOperationList;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import xl.utils.UtilsGC;
	
	public class MediatorOperationListFrame extends Mediator implements IMediator
	{
		public static const NAME:String = "MediatorOperationListFrame";
		
		private var _frame:FrameOperationList=null;
		
		public function MediatorOperationListFrame(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			
			
		}
		
		public function get frame():FrameOperationList
		{
			return _frame;
		}

		override public function listNotificationInterests():Array
		{
			// TODO Auto Generated method stub
			return [
				Notifications.MEDIATOR_TO_INIT_OPERATION_LIST,
				Notifications.MEDIATOR_TO_SHOW_OPERATION_LIST,
				Notifications.MEDIATOR_UPDATE_OPERATION_LIST
			];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			// TODO Auto Generated method stub
			super.handleNotification(notification);
			
			switch(notification.getName())
			{
				case Notifications.MEDIATOR_TO_INIT_OPERATION_LIST:
					if(_frame)
					{
						UtilsGC.clearObject(_frame);
						_frame=null;
					}
					_frame = new FrameOperationList();
					_frame.visible=false;
					break;
				case Notifications.MEDIATOR_TO_SHOW_OPERATION_LIST:
					Global.uiLayer.addElement(_frame);
					ProxyAuth.getInstance().getOperationList();
					break;
				case Notifications.MEDIATOR_UPDATE_OPERATION_LIST:
					_frame.update(notification.getBody() as ArrayCollection);
					_frame.show();
					break;
			}
		}
		
		
	}
}